package com.dily.study.demo.struct;

import java.util.Stack;

/**
 * Date: 2022-08-17 星期三
 * Time: 14:58
 * Author: Dily_Su
 * Remark: 栈
 */
public class StackDemo {

    /**
     * 栈<br>
     * 后进先出
     * 底层使用 Vector 存储数据, 所以线程安全
     * 主要关注于栈顶元素
     */
    Stack<Object> stack = new Stack<>();


    public static void main(String[] args) {
        StackDemo stackDemo = new StackDemo();
        String in = "Integer";

        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0) {
                stackDemo.stack.push(in + " >> " + i);
                System.out.println("进栈: " + in + " << " + i );
            } else {
                System.out.println("出栈: " + stackDemo.stack.pop());
            }
        }
    }
}
